<?php


namespace App\Http\Controllers\Admin;
use App\Http\Controllers\BaseController;
use App\Models\Category;
use Illuminate\Http\Request;

class CategoryController extends BaseController
{

    /**
     * 列表
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request) {
        $parent_id = $request->input('parent_id', 0);
        $title = $request->input('title');
        $list = Category::when($title, function ($q) use($title) {
            $q->where('title', 'like', '%' . $title . '%');
        })->where('parent_id', $parent_id)
            ->orderBy("sort", "desc")->orderBy("id", "asc")
            ->paginate(per_page());
        return $this->paginate($list);
    }

}

